package com.neu.wms.security;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.neu.wms.util.ResultVo;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author DAIJUNQIANG
 * @version 1.0
 * @description TODO
 * @date 2023/7/3 15:58
 */
public class LoginAuthenticationFailureHandler extends SimpleUrlAuthenticationFailureHandler {

	@Override
	public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException {
		response.setContentType("application/json;charset=UTF-8");
		String string = new ObjectMapper().writeValueAsString(ResultVo.error("请检查用户名、密码是否正确"));
		response.getWriter().println(string);
	}


}
